﻿using Microsoft.Extensions.Configuration;

namespace WorkTool.Helpers
{
    public static class SettingsHelper
    {
        public static FileSettings _fileSettings;

        public static List<CherryPickSettings> _cherryPickSettings;

        public static WorkMonthlyReportSettings _workMonthlyReportSettings;

        public static HolidayStatisticsSettings _holidayStatisticsSettings;

        public static List<CalendarSettings> _calendarSettings;

        /// <summary>
        /// 更新配置
        /// </summary>
        /// <param name="config"></param>
        public static void ChangeSettings(IConfigurationRoot config)
        {
            var fileSettings = config.GetSection("FileSettings").Get<FileSettings>();
            if (!fileSettings.SaveFolder.Equals(_fileSettings?.SaveFolder))
                fileSettings.SaveFolder = ToolHelper.CreateDirectory(fileSettings.SaveFolder);
            _fileSettings = fileSettings;
            _cherryPickSettings = config.GetSection("CherryPick").Get<List<CherryPickSettings>>();
            _workMonthlyReportSettings = config.GetSection("WorkMonthlyReport").Get<WorkMonthlyReportSettings>();
            _holidayStatisticsSettings = config.GetSection("HolidayStatistics").Get<HolidayStatisticsSettings>();
            _calendarSettings = config.GetSection("CalendarSettings").Get<List<CalendarSettings>>();
        }
    }

    public class AllSettings
    {
        public FileSettings FileSettings { get; set; }

        public List<CherryPickSettings> CherryPick { get; set; }
        public WorkMonthlyReportSettings WorkMonthlyReport { get; set; }
        public HolidayStatisticsSettings HolidayStatistics { get; set; }
    }

    /// <summary>
    /// git cherry-pick
    /// </summary>
    public class CherryPickSettings
    {
        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName { get; set; }

        /// <summary>
        /// 项目地址
        /// </summary>
        public string ProjectPath { get; set; }

        /// <summary>
        /// 作者或邮箱
        /// </summary>
        public string Author { get; set; }

        /// <summary>
        /// 分支集合
        /// </summary>
        public List<string> Branches { get; set; } = [];
    }

    /// <summary>
    /// 工作月报
    /// </summary>
    public class WorkMonthlyReportSettings
    {
        /// <summary>
        /// 部门
        /// </summary>
        public string BU { get; set; }

        /// <summary>
        /// 英文名
        /// </summary>
        public string EnglishName { get; set; }

        /// <summary>
        /// 中文名
        /// </summary>
        public string ChineseName { get; set; }

        /// <summary>
        /// 工号
        /// </summary>
        public string StaffCode { get; set; }

        /// <summary>
        /// 作者或邮箱
        /// </summary>
        public string Author { get; set; }

        /// <summary>
        /// 项目信息
        /// </summary>
        public List<WorkMonthlyReportProjectSettings> Project { get; set; } = [];
    }

    /// <summary>
    /// 项目信息
    /// </summary>
    public class WorkMonthlyReportProjectSettings
    {
        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName { get; set; }

        /// <summary>
        /// 项目编号
        /// </summary>
        public string ProjectCode { get; set; }

        /// <summary>
        /// 项目信息
        /// </summary>
        public List<WorkMonthlyReportProjectGitSettings> ProjectGit { get; set; } = [];
    }

    /// <summary>
    /// 项目信息
    /// </summary>
    public class WorkMonthlyReportProjectGitSettings
    {
        /// <summary>
        /// 项目地址
        /// </summary>
        public string ProjectPath { get; set; }

        /// <summary>
        /// 分支
        /// </summary>
        public string Branch { get; set; }
    }

    public class HolidayStatisticsSettings
    {
        /// <summary>
        /// 用户名
        /// </summary>
        public string Username { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 津贴请假类型备注；1：全部填写；2：只填写请假日期；3：只填写有津贴的日期；
        /// </summary>
        public int AllowanceRemarks { get; set; }
    }
}